<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>


    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Retrieving a Yahoo! Weather RSS Feed</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="../../build/event/event-min.js"></script>
<script type="text/javascript" src="../../build/connection/connection-min.js"></script>

<!--there is no custom header content for this example-->

</head>

<body class="yui-skin-sam">


<h1>Retrieving a Yahoo! Weather RSS Feed</h1>

<div class="exampleIntro">
	<p>This example demonstrates how to use the <a href="http://developer.yahoo.com/yui/connection/">Connection Manager</a> and a PHP proxy &mdash; to work around XMLHttpRequest's same-domain policy &mdash; to retrieve an XML document from <code>http://xml.weather.yahoo.com/forecastrss</code>.</p>

<p>To try out the example, fill in your five-digit US zip code, or Location ID.</p>			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<form id="wForm">
<fieldset>
	<label>Zip Code or Location ID</label> <input type="text" name="zip" value="94089">
	<p>Please enter a U.S. Zip Code or a location ID to get the current temperature.  The default is Zip Code 94089 for Sunnyvale, California; its location ID is: USCA1116.</p>
</fieldset>
<div id="weatherModule"></div>
<input type="button" value="Get Weather RSS" onClick="getModule()">
</form>
<script>
var div = document.getElementById('weatherModule');
var oForm = document.getElementById('wForm');

function successHandler(o){
	YAHOO.log("Success handler called; handler will parse the retrieved XML and insert into DOM.", "info", "example");

	var root = o.responseXML.documentElement;
	var oTitle = root.getElementsByTagName('description')[0].firstChild.nodeValue;
	var oDateTime = root.getElementsByTagName('lastBuildDate')[0].firstChild.nodeValue;
	var descriptionNode = root.getElementsByTagName('description')[1].firstChild.nodeValue;

	div.innerHTML = "<p>" + oTitle + "</p>" + "<p>" + oDateTime + "</p>" + descriptionNode;

	YAHOO.log("Success handler is complete.", "info", "example");
}

function failureHandler(o){
	YAHOO.log("Failure handler called; http status: " + o.status, "info", "example");

	div.innerHTML = o.status + " " + o.statusText;
}

function getModule(){
	var iZip = oForm.elements['zip'].value;
	var entryPoint = 'assets/weather.php';
	var queryString = encodeURI('?p=' + iZip);
	var sUrl = entryPoint + queryString;

	YAHOO.log("Submitting request; zip code: " + iZip, "info", "example");

	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, { success:successHandler, failure:failureHandler });
}
YAHOO.log("When you retrieve weather RSS data, relevant steps in the process will be reported here in the logger.", "info", "example");

</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
